<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>添加用户</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">昵称</td><td class="content_right"><input name="uname" class="input" placeholder="请输入昵称"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input name="uphonenumber" class="input" placeholder="请输入手机号码"></td>
					</tr>
					<tr>
						<td class="text-right">身份证号码</td><td class="content_right"><input name="uidcardnum" class="input" placeholder="请输入身份证号码"></td>
					</tr>
					<tr>
						<td class="text-right">密码</td><td class="content_right"><input name="upassword" class="input" placeholder="请输入密码"></td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span id="submitBtn" class="btn btn-info">立即提交</span> <span id="resetBtn" class="btn">重置</span> </td>
					</tr>
				</table>
				
				
			</div>
		</div>
		<script src="../../assets/layui.all.js"></script>
		<script src="/qrcode/jquery2.1.4.js"></script>
		<script src="/layer/layer.js"></script>
		<script>
			//表单验证变量
			var flag_name;
			var flag_tel;
			var flag_idcard;
			var flag_pwd;
			//表单验证方法
			function checkSubmit(){
				$("input:eq(0)").blur(function () {
					if ($(this).val() == ""){
						layer.tips("姓名不能为空!",$(this),{tipsMore:true,tips:1});
						flag_name = false;
					}else if ($(this).val().length > 20){
						layer.tips("姓名长度在20个字符以内!",$(this),{tipsMore:true,tips:1});
						flag_name = false;
					}else {
						flag_name = true;
					}
				});
				$("input:eq(1)").blur(function () {
					var reg_tel = /^1[3-9](\d){9}$/;
					if ($(this).val() == ""){
						layer.tips("手机号不能为空!",$(this),{tipsMore:true,tips:1});
						flag_tel = false;
					}else if (!reg_tel.test($(this).val())){
						layer.tips("请输入正确的11位手机号!",$(this),{tipsMore:true,tips:1});
						flag_tel = false;
					}else {
						flag_tel = true;
					}
				});
				$("input:eq(2)").blur(function () {
					var reg_id = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
					if ($(this).val() == ""){
						layer.tips("身份证号不能为空!",$(this),{tipsMore:true,tips:1});
						flag_idcard = false;
					}else if (!reg_id.test($(this).val())){
						layer.tips("请输入正确的身份证号!",$(this),{tipsMore:true,tips:1});
						flag_idcard = false;
					}else {
						flag_idcard = true;
					}
				});
				$("input:eq(3)").blur(function () {
					var reg_pwd = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*])[\da-zA-Z~!@#$%^&*]{8,20}$/;
					if ($(this).val() == ""){
						layer.tips("密码不能为空!",$(this),{tipsMore:true,tips:1});
						flag_pwd = false;
					}else if (!reg_pwd.test($(this).val())){
						layer.tips("密码必须包含数字、英文字母、特殊符号且在8~20位字符之间!",$(this),{tipsMore:true,tips:1});
						flag_pwd = false;
					}else {
						flag_pwd = true;
					}
				})
			};

			$(function () {
				checkSubmit();
				$("#submitBtn").click(function () {
					$("input:eq(0),input:eq(1),input:eq(2),input:eq(3)").trigger("blur");
					if (flag_name && flag_tel && flag_idcard && flag_pwd) {
						var windowId = layer.load();
						var uname = $("input:eq(0)").val();
						var uphonenumber = $("input:eq(1)").val();
						var uidcardnum = $("input:eq(2)").val();
						var upassword = $("input:eq(3)").val();
						$.getJSON("/user/insert.do", {
							uname: uname,
							uphonenumber: uphonenumber,
							uidcardnum: uidcardnum,
							upassword: upassword
						}, function (data) {
							layer.close(windowId);
							layer.msg(data.result);
							if (data.status == 0) {
								//录入成功
								//恢复表单的默认状态
								$("input").val("");
							}
						});
					}else {
						layer.msg("用户信息不符合要求!");
					}
					return false;
				});

				$("#resetBtn").click(function () {
					$("input").val("");
				});
			});
		</script>
	</body>
</html>
